//
//  AccountAndSafetyViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/12.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "AccountAndSafetyViewController.h"

#import "AccountAndSafetyTableViewCell.h"
#import "Binding_MobilePhoneViewController.h"
#import "Edit_PassWordViewController.h"
#import "AccountProtectionViewController.h"

@interface AccountAndSafetyViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation AccountAndSafetyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"账号与安全";
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 35, 15)];
    lbl_return.text = @"设置";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[AccountAndSafetyTableViewCell class] forCellReuseIdentifier:@"cell_account"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0 || indexPath.row == 2 || indexPath.row == 5)
    {
        return 10;
    }
    else if(indexPath.row == 7 || indexPath.row == 9)
    {
        return 35;
    }
    else
    {
        return 50;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0 || indexPath.row == 2 || indexPath.row == 5)
    {
        UITableViewCell * cell = [[UITableViewCell alloc] init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
        return cell;
    }
    else if(indexPath.row == 1)
    {
        AccountAndSafetyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_account" forIndexPath:indexPath];
        cell.lbl_name.text = @"绑定手机号";
        
        cell.lbl_tel.hidden = NO;
        cell.lbl_tel.text = @"1866999XXXX";
        
        cell.icon_return.hidden = NO;
        
        return cell;
    }
    else if(indexPath.row == 3)
    {
        AccountAndSafetyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_account" forIndexPath:indexPath];
        cell.lbl_name.text = @"账号保护";
        cell.icon_return.hidden = NO;
        cell.view_Line.hidden = NO;
        
        return cell;
    }
    else if(indexPath.row == 4)
    {
        AccountAndSafetyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_account" forIndexPath:indexPath];
        cell.lbl_name.text = @"修改密码";
        cell.icon_return.hidden = NO;
        
        return cell;
    }
    else if(indexPath.row == 6)
    {
        AccountAndSafetyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_account" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.lbl_name.text = @"开启密码锁屏";
        cell.switch_right.hidden = NO;
        cell.switch_right.tag = 100;
        [cell.switch_right addTarget:self action:@selector(switch_rightAction:) forControlEvents:(UIControlEventValueChanged)];
        
        return cell;
    }
    else if(indexPath.row == 8)
    {
        AccountAndSafetyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_account" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.lbl_name.text = @"开启Touch ID指纹解锁";
        cell.switch_right.hidden = NO;
        cell.switch_right.tag = 1000;
        [cell.switch_right addTarget:self action:@selector(switch_rightAction:) forControlEvents:(UIControlEventValueChanged)];

        return cell;
    }
    else if(indexPath.row == 7)
    {
        UITableViewCell * cell = [[UITableViewCell alloc] init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
        UILabel * lbl_detail = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH - 30, 15)];
        lbl_detail.text = @"开启后，需使用登录密码解锁XXXX";
        lbl_detail.textColor = [UIColor grayColor];
        lbl_detail.font = [UIFont systemFontOfSize:12];
        [cell addSubview:lbl_detail];
        
        return cell;
    }
    else
    {
        UITableViewCell * cell = [[UITableViewCell alloc] init];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor groupTableViewBackgroundColor];

        UILabel * lbl_detail = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH - 30, 15)];
        lbl_detail.text = @"开启后，可使用Touch ID验证需要密码验证的页面";
        lbl_detail.textColor = [UIColor grayColor];
        lbl_detail.font = [UIFont systemFontOfSize:12];
        [cell addSubview:lbl_detail];
        
        return cell;
    }
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if(indexPath.row == 1)
    {
//        NSLog(@"点击进入绑定手机号界面");
        
        Binding_MobilePhoneViewController * binding_MobilePhoneViewController = [[Binding_MobilePhoneViewController alloc] init];
        [self showViewController:binding_MobilePhoneViewController sender:nil];

    }
    else if(indexPath.row == 3)
    {
//        NSLog(@"点击进入账号保护界面");
        AccountProtectionViewController * accountProtectionViewController = [[AccountProtectionViewController alloc] init];
        [self showViewController:accountProtectionViewController sender:nil];
    }
    else if(indexPath.row == 4)
    {
//        NSLog(@"点击进入修改密码界面");
        Edit_PassWordViewController * edit_PassWordViewController = [[Edit_PassWordViewController alloc] init];
        [self showViewController:edit_PassWordViewController sender:nil];
    }
}

#pragma mark - switch点击方法
- (void )switch_rightAction:(UISwitch *)sender
{
    if(sender.tag == 100)
    {//密码锁
        if(sender.on == 0)
        {
            NSLog(@"关闭密码锁");
        }
        else
        {
            NSLog(@"开启密码锁");
        }
    }
    else
    {//指纹锁
        if(sender.on == 0)
        {
            NSLog(@"关闭指纹锁");
        }
        else
        {
            NSLog(@"开启指纹锁");
        }
    }
}















@end
